package com.groupten.ServiceImpl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.groupten.Dao.DictDataDao;
import com.groupten.Entity.DictDataEntity;
import com.groupten.Service.DictDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("dictDataService")
public class DictDataServiceImpl extends ServiceImpl<DictDataDao, DictDataEntity> implements DictDataService {

    @Autowired
    private DictDataDao dictDataDao;

    @Override
    public Boolean insert(DictDataEntity dictDataEntity) {
        int insert = dictDataDao.insert(dictDataEntity);
        return insert>0;
    }

    @Override
    public IPage<DictDataEntity> queryByType(String type, Integer page, Integer limit) {
        LambdaQueryWrapper<DictDataEntity> dictDataEntityLambdaQueryWrapper = new LambdaQueryWrapper<DictDataEntity>().eq(type!=null && !type.isEmpty(),DictDataEntity::getDictType, type);

        int curpage=1;
        int curlimit=10;
        if (page!=null&&page>0){
            curpage=page;
        }
        if (limit!=null&&limit>0){
            curlimit=limit;
        }
        return dictDataDao.selectPage(new Page<DictDataEntity>(curpage, curlimit), dictDataEntityLambdaQueryWrapper);
    }

    @Override
    public DictDataEntity queryByLabel(String label) {
        LambdaQueryWrapper<DictDataEntity> dictDataEntityLambdaQueryWrapper = new LambdaQueryWrapper<DictDataEntity>().eq(label!=null && !label.isEmpty(),DictDataEntity::getDictLabel, label);
        return dictDataDao.selectOne(dictDataEntityLambdaQueryWrapper);
    }

    @Override
    public DictDataEntity queryById(Integer id) {
        LambdaQueryWrapper<DictDataEntity> dictDataEntityLambdaQueryWrapper = new LambdaQueryWrapper<DictDataEntity>().eq(id!=null,DictDataEntity::getDictId, id);
        return dictDataDao.selectOne(dictDataEntityLambdaQueryWrapper);
    }

    @Override
    public Integer deleteById(Integer id) {
        return dictDataDao.deleteById(id);
    }

    @Override
    public Integer deleteByType(String type) {
        LambdaQueryWrapper<DictDataEntity> dictDataEntityLambdaQueryWrapper = new LambdaQueryWrapper<DictDataEntity>().eq(type!=null && !type.isEmpty(),DictDataEntity::getDictType, type);
        return dictDataDao.delete(dictDataEntityLambdaQueryWrapper);
    }

    @Override
    public Integer deleteByTypeAndLabel(String type, String label) {
        LambdaQueryWrapper<DictDataEntity> dictDataEntityLambdaQueryWrapper = new LambdaQueryWrapper<DictDataEntity>().eq(type!=null && !type.isEmpty(),DictDataEntity::getDictType, type).eq(label!=null && !label.isEmpty(),DictDataEntity::getDictLabel,label);
        return dictDataDao.delete(dictDataEntityLambdaQueryWrapper);
    }
}
